package com.squirrel.michale;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/2/13 7:40 PM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode0094 {

   /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> integerList = new ArrayList<>();
        if (root != null) {
            Stack<TreeNode> stack = new Stack<>();
            while (!stack.isEmpty() || root != null) {
                if (root != null) {
                    stack.push(root);
                    root = root.left;
                } else {
                    root = stack.pop();
                    integerList.add(root.val);
                    root = root.right;
                }
            }
        }
        return integerList;
    }
}
